<template>
  <div class="divBox">
    <el-card class="box-card">
      <el-form inline size="small" @submit.native.prevent>
        <el-form-item label="选择时间">
          <template>
            <div class="block">
              <!-- <span class="demonstration">默认</span> -->
              <el-date-picker
                v-model="time"
                type="datetimerange"
                range-separator="至"
                beginTime="开始日期"
                ednTime="结束日期"
                value-format="yyyy-MM-dd">
              </el-date-picker>
            </div>
          </template>
        </el-form-item>

        <el-form-item>
          <el-button icon="el-icon-search" size="mini" type="primary" @click="handleSearch">搜索</el-button>
          <!-- <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button> -->
        </el-form-item>
        <el-form-item class="el-form-item-align-right">
          <el-button icon="el-icon-circle-plus" size="mini" type="primary" @click="handlerOpenEdit(0)" v-hasPermi="['admin:notice:save']">添加电话回访记录</el-button>
        </el-form-item>
      </el-form>



      <el-table :data="listData.list" v-loading="loading" size="mini" :header-cell-style=" {fontWeight:'bold',background:'#f8f8f9',color: '#515a6e',height:'40px'}" border>
        <el-table-column
          prop="id"
          label="ID"
          width="50"
        />
        <el-table-column label="回访人" prop="visitPerson" min-width="90"/>
        <el-table-column label="回访电话" prop="visitTel" min-width="100"/>
        <el-table-column label="回访时间" prop="visitTime" min-width="140"/>
        <!-- <el-table-column label="备注" prop="notes" min-width="120"/> -->
        <el-table-column prop="notes" label="基本情况" min-width="100">
          <!-- <template slot-scope="scope">
            <div class="content" :class="{showMore:!scope.row.show}">{{scope.row.notes | filterEmpty}}</div>
            <span @click="showMore(scope.row,true)" v-show="!scope.row.show && scope.row.notes" style="color:#0080ff;cursor:pointer;">显示更多</span>
            <span @click="showMore(scope.row,false)" v-show="scope.row.show && scope.row.notes" style="color:#0080ff;cursor:pointer;">收起</span>
          </template> -->
        </el-table-column>

        <el-table-column label="更新时间" prop="upTime" min-width="120">
          <template slot-scope="scope">
            <span>{{ scope.row.upTime | filterEmpty }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" min-width="200"  fixed="right">
          <template slot-scope="scope">
            <el-button icon="el-icon-edit" type="primary" size="mini" @click="handlerOpenEdit(1,scope.row)" v-hasPermi="['admin:notice:info']">编辑</el-button>
            <el-button icon="el-icon-delete" type="danger" size="mini" @click="handlerOpenDel(scope.row)" v-hasPermi="['admin:notice:delete']">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="listPram.page"
        :page-sizes="constants.page.limit"
        :layout="constants.page.layout"
        :total="listData.count"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </el-card>
    <el-dialog
      :visible.sync="editDialogConfig.visible"
      :title="editDialogConfig.isCreate === 0? '添加回访记录':'编辑回访记录'"
      destroy-on-close
      :complaintId='complaintId'
      :isCreate="editDialogConfig.isCreate"
      :close-on-click-modal="false"
      :append-to-body="true"
      width="1000px"
    >
      <edit4
        v-if="editDialogConfig.visible"
        :isCreate="editDialogConfig.isCreate"
        :editData = 'editDialogConfig.editData'
        @hideEditDialog="hideEditDialog"
        :complaintId1 = 'this.id'
      />
    </el-dialog>

  </div>
</template>

<script>
import * as roleApi from '@/api/role.js'
import * as noticeApi from '@/api/noticeApi.js'
import * as visitRecord from '@/api/visitRecord.js'
import edit from './edit'
import edit4 from './edit4-edit'
import { checkPermi } from "@/utils/permission";
import bus from '@/api/bus.js'
import * as selfUtil from "@/utils/ZBKJIutil";
import * as categoryApi from "@/api/categoryApi";
import { string } from 'jszip/lib/support' // 权限判断函数
export default {
  // name: "index"
  components: { edit ,edit4},
  data() {
    return {
      aId:'',
      complaintId1:'',
      time: [],
      beginTime: '',
      endTime: '',
      constants:this.$constants,
      loading:false,
      listData: { list: [] },
      listPram: {
        complaintId: 1,
        beginTime:"",
        endTime:"",
        page: 0,
        limit:10
      },
      isCreate:0,
      editDialogConfig: {
        visible: false,
        isCreate: 0, // 0=创建，1=编辑
        editData: {}
      },
    }
  },
  props:['id','complaintId'],

  mounted() {
    this.complaintId1 =this.id
    this.handleGetVisitRecordList()

  },
  methods: {
    sendMsg(){
      // 触发绑定的事件，并向外传递参数。
      bus.$emit('getComplaintId','this.id')
    },
    checkPermi,
    showMore (row, flag) {
      this.$set(row,'show',flag)
    },
    handleSearch() {
      this.listPram.page = 1
      this.handleGetVisitRecordList()
    },
    handleSizeChange(val) {
      this.listPram.limit = val
      this.handleGetVisitRecordList()
    },
    handleCurrentChange(val) {
      this.listPram.page = val
      this.handleGetVisitRecordList()
    },
    handlerOpenDel(rowData) {
      this.$confirm('确认删除当前数据').then(() => {
        const _pram = { id: rowData.id}
        visitRecord.deleteVisitRecords(_pram).then(data => {
          this.$message.success('删除数据成功')
          this.handleGetVisitRecordList()
        })
      })
    },

    handleGetVisitRecordList() {
      if(this.time.length>0){
      this.listPram.beginTime=this.time[0]
      this.listPram.endTime=this.time[1]
      }
      console.log("complaintId:"+this.id)
      this.listPram.complaintId = this.id
      visitRecord.getVisitRecordsList(this.listPram).then(data => {
        this.listData = data
     })
    },
    handlerOpenEdit(id, editData) {
      this.editDialogConfig.editData = editData
      this.editDialogConfig.isCreate = id
      this.editDialogConfig.visible = true
    },
    hideEditDialog() {
      this.editDialogConfig.visible = false
      this.handleGetVisitRecordList()
    },
    resetQuery(){
      this.listPram.title = '';
      this.handleGetVisitRecordList()
    }
  }
}
</script>

<style scoped lang="scss">

.selWidth{
  width:150px;
}
.content .showMore{
  display:block;
  width:100%;
  word-break:keep-all;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}
</style>
